package com.gitee.zycra.future.job.common.param;

import com.gitee.zycra.future.job.common.model.JobSchedule;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;

/**
 * @author zycra
 */
@Getter
@Setter
@ToString
@Accessors(chain = true)
public class AddScheduleParam {

    /**
     * 元数据ID
     */
    @NotNull(message = "元数据ID不能为空")
    private Long jobMetaDataId;

    /**
     * 调度名称
     */
    @NotNull(message = "调度名称不能为空")
    private String scheduleName;

    /**
     * 执行参数
     */
    private String scheduleParam;

    /**
     * 是否开启(0:否,1:是)
     */
    @NotNull(message = "是否开启不能为空")
    private Boolean scheduleEnable;

    /**
     * 月
     */
    private Integer cronMonth;

    /**
     * 日
     */
    private Integer cronDay;

    /**
     * 时
     */
    private Integer cronHour;

    /**
     * 分
     */
    private Integer cronMinute;

    /**
     * 秒
     */
    private Integer cronSecond;

    public static JobSchedule convertToJobSchedule(AddScheduleParam addScheduleParam, LocalDateTime normalScheduleTime) {
        if (addScheduleParam == null) {
            return null;
        }
        return new JobSchedule().setJobMetaDataId(addScheduleParam.getJobMetaDataId())
                .setScheduleName(addScheduleParam.getScheduleName())
                .setScheduleParam(addScheduleParam.getScheduleParam())
                .setScheduleEnable(addScheduleParam.getScheduleEnable())
                .setCronMonth(addScheduleParam.getCronMonth())
                .setCronDay(addScheduleParam.getCronDay())
                .setCronHour(addScheduleParam.getCronHour())
                .setCronMinute(addScheduleParam.getCronMinute())
                .setCronSecond(addScheduleParam.getCronSecond())
                .setNextScheduleTime(normalScheduleTime)
                .setNormalNextTime(normalScheduleTime);
    }

}
